#include "pointitem.h"
#include <QPainter>
#include "toolkit.h"
#include "game/gamescene.h"
#include "man/manitem.h"

pointItem::pointItem():
    m_pixmap(NULL)
{
    m_pixmap = new QImage(640,360,QImage::Format_ARGB32);
    m_pixmap->fill(0);

    m_ptimage.load(":/image/point.png","png");
}

void pointItem::render()
{
    m_pixmap->fill(0);
    QPainter p(m_pixmap);
    if(ToolKit::m_gamescene != NULL)
    {
        foreach(ManItem* item,ToolKit::m_gamescene->m_manlist)
        {
            if(item != NULL && !item->m_linelist.isEmpty() && item->isVisible())
            {
                switch(item->m_lineTp)
                {
                case Hatch_LTP:
                {
                    foreach(QPointF pt,item->m_linelist)
                    {
                        p.drawImage(QRectF(pt,QSize(14,14)),m_ptimage,
                                    QRectF(14.0,0.0,14.0,14.0));
                    }
                }
                    break;
                case MAN_LTP:
                {
                    foreach(QPointF pt,item->m_linelist)
                    {
                        p.drawImage(QRectF(pt,QSize(14,14)),m_ptimage,
                                    QRectF(28.0,0.0,14.0,14.0));
                    }
                }
                    break;
                case PT_LTP:
                {
                    foreach(QPointF pt,item->m_linelist)
                    {
                        p.drawImage(QRectF(pt,QSize(14,14)),m_ptimage,
                                    QRectF(0.0,0.0,14.0,14.0));
                    }
                }
                    break;
                default:
                    break;
                }
            }
        }
    }
}

void pointItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
    painter->drawPixmap(QRectF(0.0,0.0,640.0,360.0),
                        QPixmap::fromImage(*m_pixmap),
                        QRectF(0.0,0.0,640.0,360.0));
}

QRectF pointItem::boundingRect() const
{
   return QRectF(0.0,0.0,640.0,360.0);
}
